package ch.zbw.timeline.domain;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;

/**
 * Domain class for a log entry
 */
@Entity
@SequenceGenerator(name = "id_log_entry", initialValue = 1, allocationSize = 1)
@Table(name = "log_entry")
@Data
public class LogEntry implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_log_entry", nullable = false)
	private int id;

	@Column(name = "fk_employee", nullable = true)
	private Integer employeeFk;

	@Column(name = "logtype", nullable = false)
	private String logTypeString;

	@Column(name = "description", nullable = true)
	private String description;

	@Column(name = "registred_on", nullable = true)
	private Timestamp registredOn;

	@Transient
	private LogType logType;

	@Transient
	private Employee employee;

	public LogEntry() {
	}

	public LogEntry(LogType logType, Employee employee, String description,
			Timestamp registredOn) {
		this.employeeFk = employee.getId();
		this.description = description;
		this.registredOn = registredOn;
		this.logType = logType;
		this.employee = employee;
		this.logTypeString = logType.toString();
	}
}
